// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './vuex/store'
import $conf from 'configuration'
import { LoadingPlugin } from 'vux'
import fastclick from 'fastclick'
import MintUI from 'mint-ui'
Vue.config.productionTip = false
fastclick.attach(document.body)
Vue.use(LoadingPlugin);
Vue.use(MintUI)
    // 定义共有过滤器(全局过滤器) 来实现日期字符串的格式化操作
Vue.filter('datefmt', (input, fmtstring) => {
    var mydate = new Date(input);
    var y = mydate.getFullYear();
    var m = mydate.getMonth() + 1;
    var d = mydate.getDate();
    if (fmtstring == 'YYYY-MM-DD') {
        return y + '-' + m + '-' + d;
    }
});
/*
 * @param {Object} target 目标对象。
 * @param {Object} source 源对象。
 * @param {boolean} deep 是否复制(继承)对象中的对象。
 * @returns {Object} 返回继承了source对象属性的新对象。
 */
Vue.copy = function(target, source, deep) {
    target = target || {};
    var sType = typeof source,
        i = 1,
        options
    if (sType === 'undefined' || sType === 'boolean') {
        deep = sType === 'boolean' ? source : false
        source = target
        target = this
    }
    if (typeof source !== 'object' && Object.prototype.toString.call(source) !== '[object Function]')
        source = {}
    while (i <= 2) {
        options = i === 1 ? target : source
        if (options != null) {
            for (var name in options) {
                var src = target[name],
                    copy = options[name]
                if (target === copy)
                    continue;
                if (deep && copy && typeof copy === 'object' && !copy.nodeType)
                    target[name] = this.copy(src ||
                        (copy.length != null ? [] : {}), copy, deep)
                else if (copy !== undefined)
                    target[name] = copy
            }
        }
        i++;
    }
    return target;
};

let init = () => {
    new Vue({
        el: '#app',
        router,
        store,
        template: '<App/>',
        components: { App }
    })
}

var u = navigator.userAgent
var isRunBeforeCordova = $conf.product && /MissonWebKit/.test(u) && window.location.href.indexOf("http") === -1

if (window.cordova || isRunBeforeCordova) {
    document.addEventListener('deviceready', init, false)
} else {
    init()
}